<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2019/1/8
 * Time: 16:40
 */

namespace app\admin\service;


class FileService
{
    public function eachFile($arr)
    {
        $new_arr = array();
        foreach ($arr as $key => $value){
            $value = substr($value,9);
            $new_arr[$key] = ['path' => $value];
        }
        return $new_arr;
    }

    public function delFile($data)
    {
        $str = '../public';
        $arr = json_decode($data,true);
        $error = true;
        foreach ($arr as $key => $value){
            $path = $str.$value['path'];
            $bool = unlink($path);
            if($bool == false){
                $error = false;
                break;
            }
        }
        if($error == true){
            return json([
               'code' => 200,
               'msg' => '删除成功'
            ]);
        }else{
            return json([
                'code' => 400,
                'msg' => '删除失败'
            ]);
        }
    }
}